package com.jfirer.validator.validation;

import javax.validation.ConstraintValidatorFactory;
import javax.validation.MessageInterpolator;
import javax.validation.ParameterNameProvider;
import javax.validation.TraversableResolver;
import javax.validation.Validator;
import javax.validation.ValidatorContext;
import javax.validation.ValidatorFactory;
import javax.validation.spi.ConfigurationState;
import com.jfirer.validator.PropertyValueDescriptorFactory;

public class ValidatorFactoryImpl implements ValidatorFactory
{
    private final ConfigurationState configurationState;
    private final ValidatorContext   validatorContext;
    
    public ValidatorFactoryImpl(ConfigurationState configurationState, PropertyValueDescriptorFactory propertyValueDescriptorFactory)
    {
        this.configurationState = configurationState;
        validatorContext = new ValidatorContextImpl(configurationState.getMessageInterpolator(), configurationState.getConstraintValidatorFactory(), configurationState.getParameterNameProvider(), propertyValueDescriptorFactory);
    }
    
    @Override
    public Validator getValidator()
    {
        return validatorContext.getValidator();
    }
    
    @Override
    public ValidatorContext usingContext()
    {
        return validatorContext;
    }
    
    @Override
    public MessageInterpolator getMessageInterpolator()
    {
        return configurationState.getMessageInterpolator();
    }
    
    @Override
    public TraversableResolver getTraversableResolver()
    {
        return configurationState.getTraversableResolver();
    }
    
    @Override
    public ConstraintValidatorFactory getConstraintValidatorFactory()
    {
        return configurationState.getConstraintValidatorFactory();
    }
    
    @Override
    public <T> T unwrap(Class<T> type)
    {
        throw new UnsupportedOperationException();
    }
    
    @Override
    public ParameterNameProvider getParameterNameProvider()
    {
        return configurationState.getParameterNameProvider();
    }
    
    @Override
    public void close()
    {
        throw new UnsupportedOperationException();
    }
}
